package com.ktg.web.mainData;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ktg.ktgcommon.domain.ProProcess;
import com.ktg.ktgcommon.domain.mainData.MdWorkshop;
import com.ktg.ktgcommon.domain.mainData.MdWorkstation;
import com.ktg.ktgcommon.query.QueryWorkstation;
import com.ktg.ktgcommon.result.R;
import com.ktg.service.WorkshopService;
import com.ktg.service.WorkstationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api")
public class WorkstationController {
    @Autowired
    private WorkstationService workstationService;

    @PostMapping("/workstation/checkListWorkstation")
    public R checkListWorkstation(String workstationCode, String workstationName,
                                  String workshopName, String processName,
                                  @RequestParam(defaultValue = "1") Integer pageNo,
                                  @RequestParam(defaultValue = "5") Integer pageSize) {

        Page<MdWorkstation> page = new Page<>(pageNo, pageSize);

        QueryWorkstation queryWorkstation=new QueryWorkstation();
        queryWorkstation.setWorkstationCode(workstationCode);
        queryWorkstation.setWorkstationName(workstationName);
        queryWorkstation.setProcessName(processName);
        queryWorkstation.setWorkshopName(workshopName);

        Page<MdWorkstation> selectPage =
                workstationService.selectPage(page,queryWorkstation);
        return R.OK(selectPage);
    }
    @PostMapping("/workstation/checkWorkstationById/{workstationId}")
    public R checkWorkstationById(@PathVariable Long workstationId) {
        MdWorkstation mdWorkstation=workstationService.checkWorkstationById(workstationId);
        return R.OK(mdWorkstation);
    }

    @PostMapping("/workstation/AddOrChWorkstation")
    public R AddOrChWorkstation( MdWorkstation mdWorkstation) {
        Integer integer=workstationService.AddOrChWorkstation(mdWorkstation);
        return R.OK(integer);
    }
    @DeleteMapping("/workstation/delWorkstation/{workstationId}")
    public R delWorkstation( @PathVariable Long workstationId) {
        Integer integer=workstationService.delWorkstation(workstationId);
        return R.OK(integer);
    }
    @DeleteMapping("/workstation/delWorkstationIdArray")
    public R delWorkstationIdArray( @RequestBody List<Long> arrayWorkstationId) {
        Integer integer=workstationService.delWorkstationIdArray(arrayWorkstationId);
        return R.OK(integer);
    }

}
